package com.taxsearch.util.roomutil;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * @description: 
 *
 * @author: 杜一平
 *
 * @create: 2018年9月11日-上午10:40:30
 **/
public class RoomUtil {
	/**
	 * 
	 * @Title: getCaoZuoList
	 * @Description: 获取去除排除尾号需要被操作的房间
	 * @param: @param list
	 * @param: @param removeStrings
	 * @param: @param startInt
	 * @param: @param endInt
	 * @return: void
	 * @throws
	 */
	public static void getCaoZuoList(List<String> list, String[] removeStrings,
			int startInt, int endInt) {
		for (int i = startInt; i <= endInt; i++) {
			// 截取最后一位字符
			String lastChar = String.valueOf(i).substring(
					String.valueOf(i).length() - 1);
			// 不包含去掉值才执行查询
			if (!useList(removeStrings, lastChar)) {
				list.add(String.valueOf(i));
			}
		}
	}
	public static boolean judgeNull(String s){
		if(s==null||"".equals(s)){
			return true;
		}
		return false;
	}
	
	/**
	 * 
	 * @Title: useList
	 * @Description: 判断数组是否包含某个字符串
	 * @param: @param arr
	 * @param: @param targetValue
	 * @param: @return
	 * @return: boolean
	 * @throws
	 */
	public static boolean useList(String[] arr, String targetValue) {
		return Arrays.asList(arr).contains(targetValue);
	}
	/**
	 * 
	 * @Title: getJsonMap
	 * @Description: 从请求中解析json为map
	 * @param: @param data
	 * @param: @return
	 * @return: Map<String,String>
	 * @throws
	 */
	public static Map<String, String> getJsonMap(String data) {
		GsonBuilder gb = new GsonBuilder();
		Gson g = gb.create();
		Map<String, String> map = g.fromJson(data.toString(),
				new TypeToken<Map<String, String>>() {
				}.getType());
		return map;
	}
	
	/**
	 * 
	 * @Title: validationData
	 * @Description: 校验获取jsonmap中是否有空串或者为null
	 * @param: @param map
	 * @param: @return
	 * @return: boolean
	 * @throws
	 */
	public static boolean validationData(Map<String, String> map) {
		for (String key : map.keySet()) {
			// 排除去除尾号
			if (!key.equals("removeNum") && !key.equals("RoomNum")) {
				if (map.get(key) == null || map.get(key).trim().equals("")) {
					return true;
				}
			}
		}
		return false;
	}
	
	/**
	 * 
	 * @Title: judgeRuzhu
	 * @Description: 判断操作的房间号是否是入住状态
	 * @param: @param ruzhuList
	 * @param: @param removeStrings
	 * @param: @param hotelId
	 * @param: @param startInt
	 * @param: @param endInt
	 * @return: void
	 * @throws
	 */
	public static void judgeRuzhu(List<String> ruzhuList,List<Map<String, String>> ruzhuNumList, List<String> list,
			String hotelId) {	
		// 比较需要被操作的list和入住的list中如果有冲突将其添加到新的list中
		if (ruzhuNumList.size() != 0) {
			for (Map<String, String> ruzhuMap : ruzhuNumList) {
				if (list.size() != 0) {
					for (String key : list) {
						if (ruzhuMap.get("roomnum").equals(key)) {
							ruzhuList.add(key);
						}
					}
				}
			}
		}
	}
	
	/**
	 * 
	 * @Title: getEightDateNow
	 * @Description: 获取当前八位系统时间
	 * @param: @return
	 * @return: String
	 * @throws
	 */
	public static String getEightDateNow() {
		Date d = new Date();
		SimpleDateFormat dFormat = new SimpleDateFormat("yyyyMMdd");
		String date = dFormat.format(d);
		return date;
	}
	
	/**
	 * 
	 * @Title: goBatch
	 * @Description: 获取被增加和修改的批量操作listmap
	 * @param: @param insertList
	 * @param: @param removeStrings
	 * @param: @param hotelId
	 * @param: @param max
	 * @param: @param price
	 * @param: @param startInt
	 * @param: @param endInt
	 * @return: void
	 * @throws
	 */
	public static void goBatch(List<Map<String, String>> insertList, String hotelId,
			String max, String price, List<String> list) {
		for (String key : list) {
			// 截取最后一位字符
			String lastChar = key;
			// 不包含去掉值才执行操作
			Map<String, String> mapTemp = new HashMap<String, String>();
			mapTemp.put("STATIONID", hotelId);
			mapTemp.put("ROOMNUMBER", lastChar);
			mapTemp.put("MAXPEOPLE", max);
			mapTemp.put("MONEY", price);
			// 当前人数为0
			mapTemp.put("CURRENTPEOPLE", "0");
			insertList.add(mapTemp);
		}
	}
	/**
	 * 
	 * @Title: goBatch
	 * @Description: 获取被增加和修改的批量操作listmap
	 * @param: @param insertList
	 * @param: @param removeStrings
	 * @param: @param hotelId
	 * @param: @param price
	 * @param: @param startInt
	 * @param: @param endInt
	 * @return: void
	 * @throws
	 */
	public static void goBatchUpdateJe(List<Map<String, String>> insertList, String hotelId,
			 String price, List<String> list) {
		for (String key : list) {
			// 截取最后一位字符
			String lastChar = key;
			// 不包含去掉值才执行操作
			Map<String, String> mapTemp = new HashMap<String, String>();
			mapTemp.put("STATIONID", hotelId);
			mapTemp.put("ROOMNUMBER", lastChar);
			mapTemp.put("MONEY", price);
			// 当前人数为0
			mapTemp.put("CURRENTPEOPLE", "0");
			insertList.add(mapTemp);
		}
	}
	/**
	 * 
	 * @Title: getIdType
	 * @Description: 对证件的listmap转为map
	 * @param: @param selectIDType 证件的listmap数据
	 * @param: @return  
	 * @return: Map<String,String>   
	 * @throws
	 */
	public static Map<String, String>getIdType(List<HashMap<String, String>>selectIDType){
		Map<String, String>idMap=new HashMap<>();
		for(int i=0;i<selectIDType.size();i++){
			Map<String, String>map=selectIDType.get(i);
			idMap.put(map.get("DI_SELNO"), map.get("DI_CVALUE"));
		}
		return idMap;
	}
}
